/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
#include <iostream>
using namespace std;
class Solution {
public:
void iscomplete(TreeNode* node,int &count){
    if(!node){return;}
    if(node->left||(!node->left&&!node->right)){
        count++;
    }
   if(node->left){iscomplete(node->left,count);}
    if(node->right){iscomplete(node->right,count);}
}
    int countNodes(TreeNode* root) {
        if(!root){return 0;}
        int count=0;
        iscomplete(root,count);
        return count;
    }
};